package cn.tworice.cryption.web;


import cn.tworice.common.vo.RequestResult;
import cn.tworice.cryption.config.CryptionProperties;
import cn.tworice.cryption.util.RSAUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("admin/cryption")
@Slf4j
@CrossOrigin
public class CryptionController {

    @Resource
    private CryptionProperties cryptionProperties;

    @GetMapping()
    public RequestResult index(){
        return RequestResult.success()
                .appendData("privateKey", RSAUtil.getPrivateKeyAsBase64(cryptionProperties.getPrivateKey()));
    }
}
